#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
const int N = 1e3 + 10;
int n, js = 1, a[N], check[N * N];
signed main() {
    cin >> n;
    for (int i = 1; i <= n; i++)cin >> a[i];
    for (int i = 1; i <= n; i++) {
        int s = 0;
        for (int j = i; j <= n; j++) {
            s += a[j];
            check[js++] = s;
        }
    }//可能有谁都不选的选法，check数组从0开始
    sort(check, check + js);
    //将他们从小到大排序，力量值之和差距最小的一定是相邻的两种选法
    //不用管区间选择重叠的情况，重叠部分相当于两种选法都没选重叠部分
    int ans = 1e12 + 10;
    for (int i = 1; i < js; i++)ans = min(ans, check[i] - check[i - 1]);
    cout << ans;
    return 0;
}